﻿using System;
using Loki.Data;
using Loki.Engine;
using Luna.Data.Configuration;

namespace Luna.Data.Test
{
    public abstract class DataWithReferenceTest<TService, TEntity> : BaseTest<TService, TEntity, IReferenceData>
        where TService : class, IDataProvider
        where TEntity : class, IDataEntity<Guid>, IReferenceData
    {
        protected const string GOOGLE_ID = "Google";

        public DataWithReferenceTest(string contextName)
            : base(contextName)
        {
        }

        public override Func<TEntity, IReferenceData> KeyGetter
        {
            get { return x => x; }
        }

        public override bool AreSame(TEntity P_Old, TEntity P_Entity2)
        {
            bool L_Return = true;

            L_Return &= P_Old.Google == P_Entity2.Google;
            L_Return &= P_Old.GoogleLastUpdate == P_Entity2.GoogleLastUpdate;
            L_Return &= (P_Old.LastUpdate - P_Entity2.LastUpdate) < TimeSpan.FromMilliseconds(2);
            L_Return &= P_Old.PK == P_Entity2.PK;
            L_Return &= P_Old.ZohoCRM == P_Entity2.ZohoCRM;
            L_Return &= P_Old.ZohoCRMLastUpdate == P_Entity2.ZohoCRMLastUpdate;

            return L_Return;
        }

        public virtual void LoadEntity(IReferenceData P_Data)
        {
            P_Data.PK = Guid.NewGuid();
            P_Data.AlreadyPersisted = false;
            P_Data.Google = GetString(GOOGLE_ID, 32);
            P_Data.GoogleLastUpdate = GetDate();
            P_Data.LastUpdate = GetDate();
            P_Data.ZohoCRM = GetInteger();
            P_Data.ZohoCRMLastUpdate = GetDate();
        }
    }
}